from email.mime import image
import UDP_utils
#from tkinter import *
import tkinter as tk
from PIL import ImageTk
from PIL.ImageGrab import grab
from threading import Thread


def recv():
    receiver = UDP_utils.RecvImage(('', 22222))
    img = UDP_utils.Image()
    data = receiver.recvImage()
    img.image_compress = data
    img.compress2decompress()
    img.bytes2image()
    return img.image


def main():
    root = tk.Tk()

    root.title('屏幕广播接收')
    root.geometry('800x700+0+0')
    lbImage = tk.Label(root)
    lbImage.pack(fill=tk.BOTH, expand=tk.YES)

    root.attributes('-topmost', True)
    def load_img(img):
        global photo
        photo = img
        width = root.winfo_width
        photo = photo.resize((1000, 700))
        photo = ImageTk.PhotoImage(photo)
        lbImage['image'] = photo
        lbImage.image = photo
        #tk.Label(root, image=photo).grid(row=0, column=0)

    while True:
        img = recv()
        thread_show = Thread(target=load_img, args=(img,))
        thread_show.daemon = True
        thread_show.start()
        root.mainloop()

    
if __name__ == '__main__':
    main()